<?php
if(defined("IZ_ACCNAME")) {
  if($_SESSION['canview'] == 1) {
    $onload .= 'listen(\'click\',\'tabfindevents\',showsearchtabfunc(\'findevents\',\'findtasks\',\'tabfindevents\'))'."\n".
               'listen(\'click\',\'tabfindtasks\',showsearchtabfunc(\'findtasks\',\'findevents\',\'tabfindtasks\'))'."\n";
    $cals .= 'Calendar.setup({inputField:"startdate",displayArea:"searchstartmousehook",button:"searchstartmousehook",firstDay:JS_FIRSTDAY});'."\n".
             'Calendar.setup({inputField:"enddate",displayArea:"searchendmousehook",button:"searchendmousehook",firstDay:JS_FIRSTDAY});'."\n";
    if($_REQUEST['mode'] == 't') {
      $mode = 't';
    } else {
      $mode = 'e';  
    }
    $title = $_REQUEST['searchtitle'];
    if(isset($_REQUEST['q'])) {
      $startany = $_REQUEST['startany'];
      $endany = $_REQUEST['endany'];
      $includecompleted = $_REQUEST['includecompleted'];
    } else {
      $startany = 1;
      $endany = 1;
      $includecompleted = 1;
    }
    ?>
      <div id="search">
      <h1 class="left"><?php echo STR_SEARCH; ?></h1>
        <div class="tabs">
          <ul class="tabmenu" id="searchmenu">
            <li><a href="#events" id="tabfindevents" <?php if($mode == 'e') { echo 'class="activetab"'; } else { echo 'class="inactivetab"'; } echo '>',STR_FINDEVENTS; ?></a></li>
            <?php if(($opt_flags & OPT_TODO) != 0) { ?>
              <li><a href="#tasks" id="tabfindtasks" <?php if($mode == 't') { echo 'class="activetab"'; } else { echo 'class="inactivetab"'; } echo '>',STR_FINDTASKS; ?></a></li>
            <?php } ?>
          </ul>
          <div class="tabcontainer">
            <form enctype="multipart/form-data" method="post" action="<?php echo $_SESSION['IZ_CALURL']; ?>index.php" id="searchform" name="searchform" onsubmit="return validate_search();">
              <fieldset>
                <legend><?php echo STR_DETAILS; ?></legend>
                <label for="searchtitle"><?php echo STR_TITLE; ?>&#58;</label>
                <input type="text" name="searchtitle" tabindex="1" id="searchtitle" class="standard" size="30" value="<?php echo $title; ?>" />
                <div class="inlineerror" id="searcherror_title">&nbsp;</div><br />
                <div id="findevents"<?php if($mode == 't') { echo ' style="display:none;"'; } ?>>
                  <label for="searchvenue"><?php echo STR_VENUE; ?>&#58;</label>
                  <input type="text" name="searchvenue" tabindex="2" id="searchvenue" class="standard" size="30" value="<?php echo $_REQUEST['searchvenue']; ?>" />
                </div>
                <div id="findtasks"<?php if($mode == 'e') { echo ' style="display:none;"'; } ?>>
                    <input type="checkbox" name="includecompleted" id="includecompleted" class="optioncheck" tabindex="3" value="1"<?php if($includecompleted) { echo ' checked="checked"'; } ?> />
                    <label for="includecompleted"><?php echo STR_INCLUDECOMPLETED; ?></label>
                </div>
              </fieldset>
              
              <fieldset>
                <legend><?php echo STR_DATE; ?></legend>
                <label for="searchstartbox"><?php echo STR_MINIMUM; ?>&#58;</label>
                <div class="datebox" id="searchstartbox">
                    <div class="dateinput">
                        <input type="text" name="startdate" tabindex="3" size="10" id="startdate" class="standard" value="<?php if(!empty($_REQUEST['startdate'])) { echo $_REQUEST['startdate']; } else { echo date("j/m/Y",mktime()); } ?>" />
                        <img src="<?php echo $_SESSION['IZ_CALURL']; ?>images/calendar.png" class="datepicker" alt="<?php echo STR_PICKSTART; ?>" id="searchstartmousehook" />
                    </div>
                    <div class="checkany">
                      <input type="checkbox" name="startany" tabindex="6" id="startany" class="inlinecheck" value="1"<?php if($startany) { echo ' checked="checked"'; } ?> />
                      <label for="startany"><?php echo STR_ANY; ?></label>
                    </div>
                </div>
                <br />
        
                <label for="searchendbox"><?php echo STR_MAXIMUM; ?>&#58;</label>
                <div class="datebox" id="searchendbox">
                    <div class="dateinput">
                      <input type="text" name="enddate" tabindex="7" size="10" id="enddate" class="standard" value="<?php if(isset($_REQUEST['enddate'])) { echo $_REQUEST['enddate']; } else { echo date("j/m/Y",mktime()); } ?>" />
                      <img src="<?php echo $_SESSION['IZ_CALURL']; ?>images/calendar.png" class="datepicker" alt="<?php echo STR_PICKEND; ?>" id="searchendmousehook" />
                    </div>
                    <div class="checkany">
                      <input type="checkbox" name="endany" tabindex="6" id="endany" value="1"<?php if($endany) { echo ' checked="checked"'; } ?> />
                      <label for="endany"><?php echo STR_ANY; ?></label>
                    </div>
                </div><br />
              </fieldset>
        
              <button type="submit" value="1" tabindex="10" name="q" class="buttonsearch"><?php echo STR_SEARCH; ?></button>
              <input type="hidden" id="mode" name="mode" value="<?php echo $mode; ?>" />
              <input type="hidden" name="act" value="search" />
            </form>
          </div><!-- end tabcontainer -->
        </div><!-- end tabs-->
    <?php if(isset($_REQUEST['q'])) {
      if(isset($_REQUEST['start'])) {
        $limstart = $_REQUEST['start'];
      } else {
        $limstart = 0;
      }
      if(!isset($_REQUEST['mode'])) {
        iz_inlineerror(ERR_ERRORTEXT.' #214: '.ERR_EVENTNONAME);
        $error = true;
      } elseif(strlen($title) == 0) {
          if($_REQUEST['mode'] == 'e') { 
            if(strlen($_REQUEST['searchvenue']) == 0) {
              iz_inlineerror(ERR_ERRORTEXT.' #215: '.ERR_EVENTNONAME);
              $error = true;
            }
          } else {
            iz_inlineerror(ERR_ERRORTEXT.' #216: '.ERR_EVENTNONAME);
            $error = true;
          }
      }
      if(!$error) {
        izsql();      
        if($_REQUEST['mode'] == 'e') {
          if(IZ_CALMODE == 'mysql') {
            if($_SESSION['MYSQLi']) {
              global $dblink;
              $title = $dblink->real_escape_string($_REQUEST['searchtitle']);
              $venue = $dblink->real_escape_string($_REQUEST['searchvenue']);
              $startdate = $dblink->real_escape_string($_REQUEST['startdate']);
              $enddate = $dblink->real_escape_string($_REQUEST['enddate']);
            } else {
              $title = mysql_real_escape_string($_REQUEST['searchtitle']);
              $venue = mysql_real_escape_string($_REQUEST['searchvenue']);
              $startdate = mysql_real_escape_string($_REQUEST['startdate']);
              $enddate = mysql_real_escape_string($_REQUEST['enddate']);
            }
            $eventsql = 'SELECT * FROM events WHERE ';
            if(strlen($title) != 0) {
              $sqlparts[] = 'title LIKE \'%'.$title.'%\'';
            }
            if(strlen($venue) != 0) {
              $sqlparts[] = 'venue LIKE \'%'.$venue.'%\'';
            }
            if(!$startany) {
              $startparts = explode('/',$startdate);
              $start = mktime(0,0,0,intval($startparts[1]),intval($startparts[0]),intval($startparts[2]));
              $sqlparts[] = 'eventend > \''.$start.'\'';
            }
            if(!$endany) {
              $endparts = explode('/',$enddate);
              $end = mktime(0,0,0,intval($endparts[1]),intval($endparts[0]),intval($endparts[2]));
              $sqlparts[] = 'eventstart < \''.$end.'\'';
            }
            $eventsql .= implode(' AND ',$sqlparts);
            if($_SESSION['cpanel'] == 1) {
              $eventsql .= ' ORDER BY eventstart DESC';
            } else {
              $eventsql .= " AND ((author = '".strtolower($_SESSION['uname'])."')".$_SESSION['publicstatus'].') ORDER BY eventstart DESC';
            }
            if($_SESSION['MYSQLi']) {
              $eventres = $dblink->query($eventsql);
              if($eventres->num_rows > 0) {
                 while($sqlevent = $eventres->fetch_object()) {
                   $events[] = new event($sqlevent);
                 }
              }
            } else {
              $eventqry = mysql_query($eventsql);
              if((is_resource($eventqry)) && (mysql_num_rows($eventqry) > 0)) {
                 while($sqlevent = mysql_fetch_object($eventqry)) {
                   $events[] = new event($sqlevent);
                 }
              }
            }
          } elseif(IZ_CALMODE == 'postgre') {
            $title = pg_escape_string($_REQUEST['searchtitle']);
            $venue = pg_escape_string($_REQUEST['searchvenue']);
            $startdate = pg_escape_string($_REQUEST['startdate']);
            $enddate = pg_escape_string($_REQUEST['enddate']);
            $eventsql = 'SELECT * FROM "events" WHERE ';
            if(strlen($title) != 0) {
              $sqlparts[] = 'title ILIKE \'%'.$title.'%\'';
            }
            if(strlen($venue) != 0) {
              $sqlparts[] = 'venue ILIKE \'%'.$venue.'%\'';
            }
            if(!$startany) {
              $startparts = explode('/',$startdate);
              $start = mktime(0,0,0,intval($startparts[1]),intval($startparts[0]),intval($startparts[2]));
              $sqlparts[] = 'eventend > \''.$start.'\'';
            }
            if(!$endany) {
              $endparts = explode('/',$enddate);
              $end = mktime(0,0,0,intval($endparts[1]),intval($endparts[0]),intval($endparts[2]));
              $sqlparts[] = 'eventstart < \''.$end.'\'';
            }
            $eventsql .= implode(' AND ',$sqlparts);
            if($_SESSION['cpanel'] == 1) {
              $eventsql .= ' ORDER BY "eventstart" DESC';
            } else {
              $eventsql .= ' AND (("status" = \'Private\' AND "author" = \''.strtolower($_SESSION['uname'])."')".$_SESSION['publicstatus'].') ORDER BY "eventstart" DESC';
            }
             $eventqry = pg_query($eventsql);
        // echo $eventsql.'-'.pg_num_rows($eventqry);
             if((is_resource($eventqry)) && (pg_num_rows($eventqry) > 0)) {
                while($sqlevent = pg_fetch_object($eventqry)) {
                  $events[] = new event($sqlevent);
                }
             }
          } elseif(IZ_CALMODE == 'msq') {
              if(isset($_GET['start'])) {
                $limstart = mssql_escape_string($_GET['start']);
              } else {
                $limstart = 1;
              }
              //TODO: Implement search for MSSQL
              if($_SESSION['cpanel'] == 1) {
                if($limstart == 0) { $limstart = 1; } //to prevent division by zero
                  $eventsql = "SELECT TOP ".$_SESSION['pageafter']." * FROM (SELECT TOP ".(($_SESSION['pageafter']/$limstart) * $_SESSION['pageafter'])." * FROM events AS T1 WHERE 1 ".$_SESSION['eventcats']['filters']." ORDER BY eventstart DESC) AS T2 ORDER BY eventstart ASC";
              } else {
                  $eventsql = "SELECT TOP ".$_SESSION['pageafter']." * FROM (SELECT TOP ".(($_SESSION['pageafter']/$limstart) * $_SESSION['pageafter'])." * FROM events AS T1 WHERE ((author = '".strtolower($_SESSION['uname'])."')".$_SESSION['publicstatus'].")".$_SESSION['eventcats']['filters']." ORDER BY eventstart DESC) AS T2 ORDER BY eventstart ASC";
              }
  // echo  $eventsql;
              $eventqry = mssql_query($eventsql);
              if((is_resource($eventqry)) && (mssql_num_rows($eventqry) > 0)) {
                 while($sqlevent = mssql_fetch_object($eventqry)) {
                   $events[] = new event($sqlevent);
                 }
              }
            }
            echo '<h2 class="calwrappertext">',str_replace('{0}', count($events), STR_MATCHESFOUND),'</h2>';
            $numevents = count($events);
            $numlisted = 0;
            if($limstart+$_SESSION['pageafter'] <= $numevents) {
              $stopat = $limstart + $_SESSION['pageafter'];
            } else {
              $stopat = $numevents;
            }
            if($limstart < $numevents) {
              getmassactions();
              if(($_SESSION['delete'] > 0) || ($_SESSION['edit'] > 0) || ($_SESSION['cpanel'] == 1)) {
                echo '<input type="hidden" name="events" value="events" />';
              }
              echo '<div id="listevents">
                 <input type="hidden" name="from" value="events.act-manage.view-list" />
                 <table class="listview" id="listtable"><colgroup><col style="text-align: center; width: 50px;" /><col /><col />';
              if(($opt_flags & OPT_ENDDATE) != 0) { echo '<col /><col />'; }
              if(($opt_flags & OPT_VENUE) != 0) { echo '<col />'; }
              if(($opt_flags & OPT_CATEGORY) != 0) { echo '<col />'; }
              if($_SESSION['cust1'] != 'none') { echo '<col />'; }
              if($_SESSION['cust2'] != 'none') { echo '<col />'; }
              if($_SESSION['cust3'] != 'none') { echo '<col />'; }
              echo '</colgroup>',
                   '<thead><tr class="titleback2"><td>',STR_SELECT,'</td><td>',STR_NAME,'</td>';
              if(($opt_flags & OPT_ENDDATE) != 0) {
                echo '<td>',STR_STARTS,'</td><td>',STR_ENDS,'</td><td>',STR_DURATION,'</td>';
              } else {
                echo '<td>',STR_DATE,'</td>';
              }
              if(($opt_flags & OPT_VENUE) != 0) { echo '<td>',STR_VENUE,'</td>'; }
              if(($opt_flags & OPT_CATEGORY) != 0) { echo '<td>',STR_CATEGORY,'</td>'; }
              if($_SESSION['cust1'] != 'none') { echo '<td>',$_SESSION['cust1'],'</td>'; }
              if($_SESSION['cust2'] != 'none') { echo '<td>',$_SESSION['cust2'],'</td>'; }
              if($_SESSION['cust3'] != 'none') { echo '<td>',$_SESSION['cust3'],'</td>'; }
              echo '</tr></thead><tbody>',"\n";
              $rc = 1;                  
              for($i=$limstart;$i<$stopat;$i++) {
                $event = $events[$i];
                $itemno++;
                if(is_int($rc/2)) { 
                  echo '<tr class="even"';
                } else { 
                    echo '<tr class="odd"';
                }
                echo ' id="row'.$event->id.'" onclick="rowselect(\''.$event->id.'\')">';                   
                $rc++;
                echo '<td><input type="checkbox" id="check'.$event->id.'" name="even'.$event->id.'" value="'.$event->id.'" onclick="rowselect(\''.$event->id.'\')" /></td>
                      <td onmouseover="overlay(this, \'event'.$itemno.'\')" onmouseout="overlayclose(\'event'.$itemno.'\')">';
                if(($opt_flags & OPT_ICON) != 0 && intval($event->icon) != -1) {
                  echo '<img src="',$_SESSION['IZ_CALURL'],'/images/icons/',$icons[$event->icon],'" class="icon" />';
                }
                echo '<span class="';
                switch($_SESSION['IZ_ITEMCOLORS']) {
                  case 'c':
                    echo 'cat-'.$event->category;
                    break;
                  case 'a':
                    echo 'item-'.$event->author;
                    break;
                  case 't':
                    echo 'itemtitle';
                    break;
                }
                echo '"><a href="'.$_SESSION['IZ_CALURL'].'index.php?events=1&amp;act=viewevent&amp;event='.$event->id.'&amp;from=events&#46;act&#45;manage&#46;view&#45;list">'.$event->title.'</a></span>
                      <div id="event'.$itemno.'" class="masseventdiv">';
                      if(empty($event->description)) {
                         echo $event->title;
                       } else {
                         echo $event->description;
                       }
                echo '</div></td>';
                if(($opt_flags & OPT_ENDDATE) != 0) {
                  echo '<td>',date("Y-m-d",$event->eventstart),'</td><td>',date("Y-m-d",$event->eventend),'</td><td>';
                  if($event->allday == 1) {
                       echo STR_ALLDAYSHORT;
                  } else {
                       echo calcduration($event->eventstart,$event->eventend);
                  }
                  echo '</td>';
                } else {
                  echo '<td>',date("Y-m-d",$event->eventstart),'</td>';
                }
                if(($opt_flags & OPT_VENUE) != 0) {
                  if($event->linkgoogle == 1) {
                    echo '<td><a href="http://maps.google.co.uk/maps?q=',$event->venue,'" title="',STR_LINKGOOGLE,'">',$event->venue,'</a></td>';
                  } else {
                    echo '<td>',$event->venue,'</td>';
                  }
                }
                if(($opt_flags & OPT_CATEGORY) != 0) {
                  if($_SESSION['IZ_REWRITE'] == 'apache') {
                    echo '<td><a href="',$_SESSION['IZ_CALURL'],'category/',$event->category,'/">',$_SESSION['eventcats'][$event->category]->name,'</a></td>';
                  } else {
                    echo '<td><a href="',$_SESSION['IZ_CALURL'],'index.php&#63;category=',$event->category,'">',$_SESSION['eventcats'][$event->category]->name,'</a></td>';
                  }
                }
                if($_SESSION['cust1'] != 'none') { echo '<td>',$event->cust1,'</td>'; }
                if($_SESSION['cust2'] != 'none') { echo '<td>',$event->cust2,'</td>'; }
                if($_SESSION['cust3'] != 'none') { echo '<td>',$event->cust3,'</td>'; }
                echo '</tr>',"\n";
                $numlisted++;
              }  
              echo '</tbody></table><br />'.$limstart.' - '.$stopat.' '.STR_OF.' '.$numevents.'<br /><br />
                  </div>
                </form>';
              getpagination($numevents,$limstart);
            }
  // var_dump($events);
        } else {
          if(IZ_CALMODE == 'mysql') {
            if($_SESSION['MYSQLi']) {
              global $dblink;
              $title = $dblink->real_escape_string($_REQUEST['searchtitle']);
              $startdate = $dblink->real_escape_string($_REQUEST['startdate']);
              $enddate = $dblink->real_escape_string($_REQUEST['enddate']);
            } else {
              $title = mysql_real_escape_string($_REQUEST['searchtitle']);
              $startdate = mysql_real_escape_string($_REQUEST['startdate']);
              $enddate = mysql_real_escape_string($_REQUEST['enddate']);
            }
            $sql = 'SELECT * FROM tasks WHERE ';
            $sqlparts[] = 'title LIKE \'%'.$title.'%\'';
            if(!$includecompleted) {
              $sqlparts[] = 'complete = \'0\'';
            }
            if(!$startany) {
              $startparts = explode('/',$startdate);
              $start = mktime(0,0,0,intval($startparts[1]),intval($startparts[0]),intval($startparts[2]));
              $sqlparts[] = 'due > \''.$start.'\'';
            }
            if(!$endany) {
              $endparts = explode('/',$enddate);
              $end = mktime(0,0,0,intval($endparts[1]),intval($endparts[0]),intval($endparts[2]));
              $sqlparts[] = 'due < \''.$end.'\'';
            }
            $sql .= implode(' AND ',$sqlparts);
            if($_SESSION['cpanel'] == 1) {
              $sql .= ' ORDER BY due DESC';
            } else {
              $sql .= " AND ((author = '".strtolower($_SESSION['uname'])."')".$_SESSION['publicstatus'].') ORDER BY due DESC';
            }
  //echo $sql;
  //var_dump($sqlparts);
             if($_SESSION['MYSQLi']) {
               global $dblink;
               $qry = $dblink->query($sql);
               if($qry->num_rows > 0) {
                  while($sqlres = $qry->fetch_object()) {
                    $todos[] = new todo($sqlres);
                  }
               }
             } else {
               $qry = mysql_query($sql);
               if((is_resource($qry)) && (mysql_num_rows($qry) > 0)) {
                  while($sqlres = mysql_fetch_object($qry)) {
                    $todos[] = new todo($sqlres);
                  }
               }
             }
          } elseif(IZ_CALMODE == 'postgre') {
            $title = pg_escape_string($_REQUEST['searchtitle']);
            $startdate = pg_escape_string($_REQUEST['startdate']);
            $enddate = pg_escape_string($_REQUEST['enddate']);
            $sql = 'SELECT * FROM "tasks" WHERE ';
            $sqlparts[] = '"title" ILIKE \'%'.$title.'%\'';
            if(!$includecompleted) {
              $sqlparts[] = '"complete" = \'0\'';
            }
            if(!$startany) {
              $startparts = explode('/',$startdate);
              $start = mktime(0,0,0,intval($startparts[1]),intval($startparts[0]),intval($startparts[2]));
              $sqlparts[] = '"due" > \''.$start.'\'';
            }
            if(!$endany) {
              $endparts = explode('/',$enddate);
              $end = mktime(0,0,0,intval($endparts[1]),intval($endparts[0]),intval($endparts[2]));
              $sqlparts[] = '"due" < \''.$end.'\'';
            }
            $sql .= implode(' AND ',$sqlparts);
            if($_SESSION['cpanel'] == 1) {
              $sql .= ' ORDER BY "due" DESC';
            } else {
              $sql .= ' AND (("status" = \'Private\' AND "author" = \''.strtolower($_SESSION['uname'])."')".$_SESSION['publicstatus'].') ORDER BY "due" DESC';
            }
  //echo $sql;
  //var_dump($sqlparts);
            $qry = pg_query($sql);
            if((is_resource($qry)) && (pg_num_rows($qry) > 0)) {
              while($sqlres = pg_fetch_object($qry)) {
                $todos[] = new todo($sqlres);
              }
            }
          } elseif(IZ_CALMODE == 'msq') {
             $qry = mssql_query($sql);
             if((is_resource($qry)) && (mssql_num_rows($qry) > 0)) {
               while($sqlres = mssql_fetch_object($qry)) {
                 $todos[] = new todo($sqlres);
               }
             }
          }
          echo '<h2 class="calwrappertext">',str_replace('{0}', count($todos), STR_MATCHESFOUND),'</h2>';
           $numtasks = count($todos);
           $numlisted = 0;
           if($limstart+$_SESSION['pageafter'] <= $numtasks) {
             $stopat = $limstart + $_SESSION['pageafter'];
           } else {
             $stopat = $numtasks;
           }
           if($limstart < $numtasks) {
             getmassactions();
             if(($_SESSION['delete'] > 0) || ($_SESSION['edit'] > 0) || ($_SESSION['cpanel'] == 1)) {
               echo '<input type="hidden" name="events" value="events" />';
             }
             echo '<div id="listtodo">
                   <table class="listview" id="todotable">',"\n",'<colgroup><col style="text-align: center; width: 50px;" /><col /><col />';
                   if(($opt_flags & OPT_CATEGORY) != 0) { echo '<col />'; }
                   if($_SESSION['cust1'] != 'none') { echo '<col />'; }
                   if($_SESSION['cust2'] != 'none') { echo '<col />'; }
                   if($_SESSION['cust3'] != 'none') { echo '<col />'; }
                   echo '</colgroup>',"\n",
                        '<thead><tr class="titleback2"><td>',STR_SELECT,'</td><td>',STR_TASKNAME,'</td><td>',STR_DATEDUE,'</td>';
                   if(($opt_flags & OPT_CATEGORY) != 0) { echo '<td>',STR_CATEGORY,'</td>'; }
                   if($_SESSION['cust1'] != 'none') { echo '<td>',$_SESSION['cust1'],'</td>'; }
                   if($_SESSION['cust2'] != 'none') { echo '<td>',$_SESSION['cust2'],'</td>'; }
                   if($_SESSION['cust3'] != 'none') { echo '<td>',$_SESSION['cust3'],'</td>'; }
                   echo '</tr></thead><tbody>',"\n";
                   $rc = 1;                  
                   for($i=$limstart;$i<$stopat;$i++) {
                     $todo = $todos[$i];
                     if(is_int($rc/2)) {
                       echo '<tr class="even"';                               
                     } else {
                         echo '<tr class="odd"'; 
                     }
                     $rc++;
                     echo ' id="row'.$todo->id.'" onclick="rowselect(\''.$todo->id.'\')"><td><input type="checkbox" id="check'.$todo->id.'" name="todo'.$todo->id.'" value="'.$todo->id.'" onclick="rowselect(\''.$todo->id.'\')" /></td><td';
                     if(strlen($todo->description) > 20) {
                       echo ' onmouseover="overlay(this, \'todo'.$itemno.'\')" onmouseout="overlayclose(\'todo'.$itemno.'\')"';
                     }
                     echo '>';
                     if(($_SESSION['IZ_OPT'] & OPT_ICON) != 0 && intval($todo->icon) != -1) {
                       echo '<img src="',$_SESSION['IZ_CALURL'],'/images/icons/',$icons[$todo->icon],'" class="icon" />';
                     }
                     echo '<span class="';
                     switch($_SESSION['IZ_ITEMCOLORS']) {
                       case 'c':
                         echo 'cat-'.$todo->category;
                         break;
                       case 'a':
                         echo 'item-'.$todo->author;
                         break;
                       case 't':
                         echo 'itemtitle';
                         break;
                     }
                     echo '"><a href="',$_SESSION['IZ_CALURL'],'index.php?todo=1&amp;act=viewtodo&amp;id=',$todo->id,'&amp;from=events&#46;act&#45;manage&#46;view&#45;list">',$todo->title,'</a></span>
                          <div id="todo',$itemno,'" class="masseventdiv">',$todo->description,'</div>
                          </td><td>';
                     $itemno++;
                     if($todo->due == 0) {
                       echo STR_ONGOING;
                     } else {
                       echo date("Y-m-d",$todo->due);
                     }
                     echo '</td>';
                     if(($opt_flags & OPT_CATEGORY) != 0) {
                       if($_SESSION['IZ_REWRITE'] == 'apache') {
                         echo '<td><a href="',$_SESSION['IZ_CALURL'],'category/',$todo->category,'/">',$_SESSION['todocats'][$todo->category]->name,'</a></td>';
                       } else {
                         echo '<td><a href="',$_SESSION['IZ_CALURL'],'index.php&#63;category=',$todo->category,'">',$_SESSION['todocats'][$todo->category]->name,'</a></td>';
                       }
                     }
                     if($_SESSION['cust1'] != 'none') { echo '<td>',$todo->cust1,'</td>'; }
                     if($_SESSION['cust2'] != 'none') { echo '<td>',$todo->cust2,'</td>'; }
                     if($_SESSION['cust3'] != 'none') { echo '<td>',$todo->cust3,'</td>'; }
                     echo '</tr>',"\n";
                     $numlisted++;
                   }  
                   echo '</tbody></table><br />'.$limstart.' - '.$stopat.' '.STR_OF.' '.$numtasks.'<br /><br />
                       </div>
                     </form>';
                   getpagination($numtasks,$limstart);
             }
        }
      }
    } ?>
    </div><!-- end search -->
<?php 
  } else {
    echo '<span>&#35;220&#58; ',ERR_NOPERMISSION,'</span>';
  } 
} else {
  // Directly accessed
  header('Location: ../');
} ?>